<?php include("session.inc.php"); ?>
<?php require_once("../common/config.inc.php");?>
<?php include("../common/db.inc.php"); ?>
<?php
	init();		
	
	function init(){
		$action=$_GET["action"];		
		if($action=="delete"){
			$id=$_GET["id"];
			deleteJournal($id);
		}
	}
	
	function deleteJournal($id){
		$sql = "delete FROM medcdb.t_journal where id='$id'";
		$connection=getMEDCConnection();
		executeUpdate($sql,$connection);		
	}
	
	function getJournals(){
		$sql = "SELECT * FROM medcdb.t_journal ORDER BY createdate DESC";
		$connection=getMEDCConnection();
		$dataArray=executeQuery($sql,$connection);
		return $dataArray;
	}
		
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="keywords" content="" />
<meta name="Description" content="" />
<meta name="author" content="" />
<title>Journal List Page</title>
<link href="../css/medc.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/javascript">	
	function doGet(actionURL,actionName){
		if(actionName=="DeleteJournal"){
		    var isConfirm = window.confirm("Are you sure to delete the Journal?");
		    if (isConfirm == false) {
		        return;
		    }			
		}
		location.href=actionURL;		
	}
</script>
</head>
<body>
	<div id="toparea">
		<?php include "../common/header.inc.php"?>
	</div>	
	
	<div id="menu">
		<?php include "AdminMenu.inc.php";?>
	</div>
	<!--Main area-->
	<style>
	.mytable{width:750px;border-spacing:0;margin-left:20px;}
	.mytable th,td {border:1px solid #CCC;}
	.mytable th {background-color:#EEE;}
	</style>
	<div id="mainarea" style="margin-left:200px;">	
		<form method="get" action="" name="medcform">
		<table class="mytable">
			<thead>
				<tr>
					<th>Journal ID</th>
					<th>Journal Name</th>
					<th>Cover Image</th>
					<!--<th>Store Name</th>-->
					<th>Original Name</th>
					<th>Create Date</th>									
					<th>Brief</th>
					<th>Operate</th>
				</tr>
			</thead>
			<tbody>
				<!--
				<tr>
					<td align="center">test user1</td>
					<td align="center">3401.pdf</td>
					<td align="center">images/3401.jpg</td>	
					<td align="center">volume/3401_00000000.pdf</td>
					<td align="center">3401.pdft</td>
					<td align="center">2012-03-03</td>	
					<td align="center">brief info</td>				
					<td align="center">
						<input type="button" id="modify_x" name="modify" value="Modify" onclick=""/>
						<input type="button" id="delete_x" name="delete" value="Delete" onclick=""/>
					</td>
				</tr>
				-->
				<?php				
				$journals=getJournals();					
				$columnNames=array("id","name","facepic","originalname","createdate","brief");
				$i=0;
				foreach ($journals as $journal){	
				?>
				<tr>	
					<?php foreach ($columnNames as $colName){	?>
				<td align="center"><?php echo $journal[$colName]; ?></td>
				<?php
				}
				?>					
				<td align="center">
					<input type="button" id="modify_<?php echo $i ?>" name="modify" value="Modify" onclick="doGet('JournalModify.php?id=<?php echo $journal["id"]?>&action=modify','ModifyJournal')"/>
					<input type="button" id="delete_<?php echo $i ?>" name="delete" value="Delete" onclick="doGet('JournalList.php?id=<?php echo $journal["id"]?>&action=delete','DeleteJournal')"/>
				</td>			
			</tr>		
			<?php
			$i++;}
			?>
			</tbody>	
		</table>
		</form>		
	</div>	
	<div class="myclear"></div>
	<div id="footer">
		<?php include "../common/footer.inc.php";?>
	</div>
</body>
</html>
